(SST) ShlWAPI.pas Version 1.08

Developer Reference
(SST)ShlWAPI ColorAdjustLuma Function
Adjusts the lumninance of a RGB, COLORREF value, without altering its hue and saturation values.
Scope
Global (i.e. this function can be called/accessed from code in any unit that includes/uses (SST)ShlWAPI.pas).
Syntax
Function ColorAdjustLuma(clrRGB : COLORREF; n : Integer; fScale : BOOL) : COLORREF;  
Parameters
clrRGB [in] The (RGB) color, encoded in a COLORREF value, of which to adjust/modify the luminance.
n [in] The value, in per mille (1/1000), by which the luminance should be modified.
fScale [in] A flag that determines whether the luminance is modified relative to the luminance of the original color or specifies the absolute luminance.
If this flag is set to FALSE, the value specified in n is interpreted as the desired, absolute luminance, and n may only take on positive values in the range from 0 to 1000.
If this flag is set to TRUE, n will be interpreted as the percentage by which the original color's luminance should be in- or decreased, and both positive and negative values may be specified for n. In this case, negative values will decrease the luminance and positive values will increase it.
Return Values
A COLORREF value, in which the modified red, green, and blue (RGB) values corresponding to the modified color, is encoded.
Example
PROCEDURE TForm4.TestShlWAPIColorAdjustLuma(Sender : TObject);

VAR bmp : TBitmap;
VAR bmprect : TRect;
VAR originalcolor : COLORREF;
VAR newluma : INTEGER;
VAR modifiedcolor : COLORREF;
VAR colorname : STRING;
VAR newinfoline : STRING;

BEGIN
bmp := NIL;
FillChar(bmprect, SizeOf(bmprect), #0);
originalcolor := 0;
newluma := 0;
modifiedcolor := 0;
colorname := '';
newinfoline := '';

bmp := TBitmap.Create();
bmp.Width := 48;
bmp.Height := 48;
bmprect := Rect(0, 0, 48, 48);

originalcolor := $FF00FF;
bmp.Canvas.Brush.Color := originalcolor;
bmp.Canvas.FillRect(bmprect);
bmp.SaveToFile('OriginalColor1.bmp');
ColorToIdent(originalcolor, colorname);
newluma := 500;
newinfoline := 'ColorAdjustLuma called with 0x' + IntToHex(originalcolor, 8) +
' (' + IntToStr(originalcolor) + ')' + ' (' + colorname + ')' +
' and n = ' + IntToStr(newluma);
Memo1.Lines.Add(newinfoline);
modifiedcolor := ColorAdjustLuma(originalcolor, newluma, TRUE);
ColorToIdent(modifiedcolor, colorname);
newinfoline := 'Modified color : 0x' + IntToHex(modifiedcolor, 8) +
' (' + IntToStr(modifiedcolor) + ')' + ' (' + colorname + ')';
Memo1.Lines.Add(newinfoline);
bmp.Canvas.Brush.Color := modifiedcolor;
bmp.Canvas.FillRect(bmprect);
bmp.SaveToFile('AdjustedColor1.bmp');

originalcolor := $0000FF;
bmp.Canvas.Brush.Color := originalcolor;
bmp.Canvas.FillRect(bmprect);
bmp.SaveToFile('OriginalColor2.bmp');
ColorToIdent(originalcolor, colorname);
newinfoline := 'ColorAdjustLuma called with 0x' + IntToHex(originalcolor, 8) +
' (' + IntToStr(originalcolor) + ')' + ' (' + colorname + ')' +
' and n = ' + IntToStr(newluma);
Memo1.Lines.Add(newinfoline);
modifiedcolor := ColorAdjustLuma(originalcolor, newluma, FALSE);
ColorToIdent(modifiedcolor, colorname);
newinfoline := 'Modified color : 0x' + IntToHex(modifiedcolor, 8) +
' (' + IntToStr(modifiedcolor) + ')' + ' (' + colorname + ')';
Memo1.Lines.Add(newinfoline);
bmp.Canvas.Brush.Color := modifiedcolor;
bmp.Canvas.FillRect(bmprect);
bmp.SaveToFile('AdjustedColor2.bmp');

originalcolor := $808080;
bmp.Canvas.Brush.Color := originalcolor;
bmp.Canvas.FillRect(bmprect);
bmp.SaveToFile('OriginalColor3.bmp');
ColorToIdent(originalcolor, colorname);
newinfoline := 'ColorAdjustLuma called with 0x' + IntToHex(originalcolor, 8) +
     ' (' + IntToStr(originalcolor) + ')' + ' (' + colorname + ')' +
     ' and n = ' + IntToStr(newluma);
Memo1.Lines.Add(newinfoline);
modifiedcolor := ColorAdjustLuma(originalcolor, newluma, TRUE);
ColorToIdent(modifiedcolor, colorname);
newinfoline := 'Modified color : 0x' + IntToHex(modifiedcolor, 8) +
     ' (' + IntToStr(modifiedcolor) + ')' + ' (' + colorname + ')';
Memo1.Lines.Add(newinfoline);
bmp.Canvas.Brush.Color := modifiedcolor;
bmp.Canvas.FillRect(bmprect);
bmp.SaveToFile('AdjustedColor3.bmp');

originalcolor := $00FFFF;
bmp.Canvas.Brush.Color := originalcolor;
bmp.Canvas.FillRect(bmprect);
bmp.SaveToFile('OriginalColor4.bmp');
ColorToIdent(originalcolor, colorname);
newluma := -500;
newinfoline := 'ColorAdjustLuma called with 0x' + IntToHex(originalcolor, 8) +
     ' (' + IntToStr(originalcolor) + ')' + ' (' + colorname + ')' +
     ' and n = ' + IntToStr(newluma);
Memo1.Lines.Add(newinfoline);
modifiedcolor := ColorAdjustLuma(originalcolor, newluma, TRUE);
ColorToIdent(modifiedcolor, colorname);
newinfoline := 'Modified color : 0x' + IntToHex(modifiedcolor, 8) +
' (' + IntToStr(modifiedcolor) + ')' + ' (' + colorname + ')';
Memo1.Lines.Add(newinfoline);
bmp.Canvas.Brush.Color := modifiedcolor;
bmp.Canvas.FillRect(bmprect);
bmp.SaveToFile('AdjustedColor4.bmp');

Memo1.Lines.Add('');
bmp.Free();
END;
The above example will produce the following output:
ColorAdjustLuma called with 0x00FF00FF (16711935) (clFuchsia) and n = 500
Modified color : 0x00FF80FF (16744703) (clFuchsia)
ColorAdjustLuma called with 0x000000FF (255) (clRed) and n = 500
Modified color : 0x00FFFFFF (16777215) (clWhite)
ColorAdjustLuma called with 0x00808080 (8421504) (clGray) and n = 500
Modified color : 0x00BFBFBF (12566463) (clGray)
ColorAdjustLuma called with 0x0000FFFF (65535) (clYellow) and n = -500
Modified color : 0x00008080 (32896) (clOlive)
It should also generate the eight Windows, bitmap (.bmp) files named OriginalColor1.bmp, OriginalColor2.bmp, OriginalColor3.bmp, OriginalColor4.bmp, AdjustedColor1.bmp, AdjustedColor2.bmp, AdjustedColor3.bmp, and AdjustedColor4.bmp. shown below.
Original Color 1 OriginalColor1.bmp
Fig. 2.1.2.3.13.1.0.1
Original Color 2 OriginalColor2.bmp
Fig. 2.1.2.3.13.1.0.3
Original Color 3 OriginalColor3.bmp
Fig. 2.1.2.3.13.1.0.5
Original Color 4 OriginalColor4.bmp
Fig. 2.1.2.3.13.1.0.7
Adjusted Color 1 AdjustedColor1.bmp
Fig. 2.1.2.3.13.1.0.2
Adjusted Color 2 AdjustedColor2.bmp
Fig. 2.1.2.3.13.1.0.4
Adjusted Color 3 AdjustedColor3.bmp
Fig. 2.1.2.3.13.1.0.6
Adjusted Color 4 AdjustedColor4.bmp
Fig. 2.1.2.3.13.1.0.8
Requirements
Unit: Declared and imported in (SST)ShlWAPI.pas
Library: (SST)ShlWAPI.dcu/(SST)ShlWAPI.obj
Unicode: Not applicable.
Min. ShlWAPI.dll version according to MS SDK doc.: 5.0
Min. ShlWAPI.dll version based on SST research: 5.0
Min. OS version(s) according to Microsoft SDK doc.: Windows 2000, Windows NT 4.0 with Internet Explorer 5, Windows 98, Windows 95 with Internet Explorer 5
Min. OS version(s) according to SST research.: Windows NT 4.0 with IE 5, Windows 95 with IE 5, Windows 98 with IE 5, Windows 98 SE, Windows 2000 and later
See Also
ColorHLSToRGB, ColorRGBToHLS, SHCreateShellPalette, SHGetInverseCMAP
 
Windows APIs: ColorAdjustLuma, ColorHLSToRGB, ColorRGBToHLS, SHCreateShellPalette, SHGetInverseCMAP,


Document/Contents version 1.00
Page/URI last updated on 07.12.2023
 
Copyright © Stoelzel Software Technologie (SST) 2010 - 2017
Suggestions and comments mail to:
webmaster@stoelzelsoftwaretech.com